package demo1;

import java.util.Scanner;

public class Test3 {
    public String name = "admin";
    public String password = "123456";

    public void login(String name,String password)
            throws UserNameException, PassWordException {
        if(!this.name.equals(name)) {
            System.out.println("用户名错误！");
            throw new UserNameException();
        }
        if(!this.password.equals(password)) {
            System.out.println("密码错误！");
            throw new PassWordException();
        }
    }

    public static void main(String[] args) {
        Test3 test3 = new Test3();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String name = scanner.nextLine();
        System.out.println("请输入密码：");
        String password = scanner.nextLine();
        try {
            test3.login(name,password);
            System.out.println("登录成功");
        }catch (UserNameException userNameException) {
            userNameException.printStackTrace();
            System.out.println("用户名异常！");
        }catch (PassWordException passWordException) {
            passWordException.printStackTrace();
            System.out.println("密码异常！");
        }

    }

}
